<template>
  <div class="goods-container">
    <!-- 左侧图片区域 -->
    <div class="left">
      <img :src="items.thumb" class="avatar" alt="" />
    </div>
    <!-- 右侧商品区域 -->
    <div class="right">
      <!-- 标题 -->
      <div class="title">{{ items.name }}</div>
      <div class="info">
        <!-- 单价 -->
        <span class="price">￥{{ items.price }}</span>
        <div class="btns">
          <!-- 按钮区域 -->
          <button class="btn btn-light" @click="reduce(items)" :disabled="items.count == '1'" >-</button>
          <span class="count">{{ items.count }}</span>
          <button class="btn btn-light" @click="add(items)">+</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "CartItem",
  props: {
    items: {
      type: Object,
      default: () => {},
    },
  },
  methods: {
    add(data) {
      this.$emit("commodity", {data: data, name: "add"});
    },
    reduce(data) {
      this.$emit("commodity", {data: data, name: "reduce"});
    },
  },
  computed: {},
};
</script>

<style  scoped>
.goods-container {
  display: flex;
  padding: 10px;
}
.goods-container {
  border-top: 1px solid #f8f8f8;
}
.left {
  margin-right: 10px;
}

.avatar {
  width: 100px;
  height: 100px;
}
.right {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: 1;
}
.title {
  font-weight: bold;
}
.info {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.price {
  color: red;
  font-weight: bold;
}
.btns .count {
  display: inline-block;
  width: 30px;
  text-align: center;
}
.custom-control-label::before,
.custom-control-label::after {
  top: 3.6rem;
}
</style>
